package com.sf.web.advice;

import com.sf.domain.Employee;
import com.sf.ex.BusinessException;
import com.sf.util.JsonResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 标记这个类是异常处理类
 */
@ControllerAdvice
public class CommonControllerAdvice {

   @ExceptionHandler(Exception.class)
    @ResponseBody
    public JsonResult Handler(Exception e){
       e.printStackTrace();
       return new JsonResult(false,"操作失败",null);
   }

    /**
     * 自己定义的异常
     * @param e
     * @return
     */
    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public JsonResult Handler(BusinessException e){
        return new JsonResult(false,e.getMessage(),null);
    }
}
